package com.app.signing.view.room.data;

import android.util.SparseIntArray;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangpeifeng
 * @date 2018/05/09 15:16
 *
 * 每间教室的布局数据定义
 */
public class SeatDataUtil {

    /**
     * 二维数值定义房间座位分布
     *
     * num > 0 为座位号
     * num = 0 为桌子
     * num = -1 位置不显示
     */
    public static final int[][] ROOM_316 = {
            { 149, 150, -1, 124, 125, 126, 82, 83, 84, 40, 41, 42 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 147, 148, -1, 121, 122, 123, 79, 80, 81, 37, 38, 39 },
            { 145, 146, -1, 118, 119, 120, 76, 77, 78, 34, 35, 36 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 143, 144, -1, 115, 116, 117, 73, 74, 75, 31, 32, 33 },
            { 141, 142, -1, 112, 113, 114, 70, 71, 72, 28, 29, 30 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 139, 140, -1, 109, 110, 111, 67, 68, 69, 25, 26, 27 },
            { 137, 138, -1, 106, 107, 108, 64, 65, 66, 22, 23, 24 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 135, 136, -1, 103, 104, 105, 61, 62, 63, 19, 20, 21 }
    };

    public static final int[][] ROOM_320 = {
            { 132, 133, 134, 104, 105, 106, 70, 71, 72, 34, 35, 36 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 129, 130, 131, 101, 102, 103, 67, 68, 69, 31, 32, 33 },
            { 126, 127, 128, 98, 99, 100, 64, 65, 66, 28, 29, 30 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 123, 124, 125, 95, 96, 97, 61, 62, 63, 25, 26, 27 },
            { 93, 94, -1, 120, 121, 122, 82, 83, 84, 22, 23, 24 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 91, 92, -1, 117, 118, 119, 79, 80, 81, 19, 20, 21 },
            { 114, 115, 116, 88, 89, 90, 52, 53, 54, 16, 17, 18 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 111, 112, 113, 85, 86, 87, 49, 50, 51, 13, 14, 15 },
            { -1, -1, -1, -1, -1, -1, 46, 47, 48, 10, 11, 12 },
            { -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0 },
            { -1, -1, -1, -1, -1, -1, 43, 44, 45, 7, 8, 9 },
            { 109, 110, -1, 75, 74, 73, 40, 41, 42, 4, 5, 6 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 107, 108, -1, 78, 77, 76, 37, 38, 39, 1, 2, 3 }
    };

    public static final int[][] ROOM_212 = {
            { 231, 232, -1, 190, 191, 192, 124, 125, 126, 64, 65, 66 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 229, 230, -1, 187, 188, 189, 121, 122, 123, 61, 62, 63 },
            { 227, 228, -1, 184, 185, 186, 118, 119, 120, 58, 59, 60 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 225, 226, -1, 181, 182, 183, 115, 116, 117, 55, 56, 57 },
            { 223, 224, -1, 178, 179, 180, 112, 113, 114, 52, 53, 54 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 221, 222, -1, 175, 176, 177, 109, 110, 111, 49, 50, 51 },
            { 219, 220, -1, 172, 173, 174, 106, 107, 108, 46, 47, 48 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 217, 218, -1, 169, 170, 171, 103, 104, 105, 43, 44, 45 },
            { 215, 216, -1, 166, 167, 168, 100, 101, 102, 40, 41, 42 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 213, 214, -1, 163, 164, 165, 97, 98, 99, 37, 38, 39 },
            { 211, 212, -1, 160, 161, 162, 94, 95, 96, 34, 35, 36 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 209, 210, -1, 157, 158, 159, 91, 92, 93, 31, 32, 33 },
            { 207, 208, -1, 154, 155, 156, 88, 89, 90, 28, 29, 30 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 205, 206, -1, 151, 152, 153, 85, 86, 87, 25, 26, 27 },
            { 203, 204, -1, 148, 149, 150, 82, 83, 84, 21, 20, 19 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 201, 202, -1, 145, 146, 147, 79, 80, 81, 24, 23, 22 },
            { 199, 200, -1, 142, 143, 144, 76, 77, 78, 16, 17, 18 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 197, 198, -1, 139, 140, 141, 73, 74, 75, 13, 14, 15 },
            { 195, 196, -1, 136, 137, 138, 70, 71, 72, 10, 11, 12 },
            { 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 193, 194, -1, 133, 134, 135, 67, 68, 69, 7, 8, 9 },
            { -1, -1, -1, 130, 131, 132, -1, -1, -1, 4, 5, 6 },
            { -1, -1, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0 },
            { -1, -1, -1, 127, 128, 129, -1, -1, -1, 1, 2, 3 }
    };

    public static List<List<RoomSeatData>> buildData(int[][] datas) {
        List<List<RoomSeatData>> list = new ArrayList<>();
        for (int i = 0; i < datas.length; i++) {
            int[] seats = datas[i];
            if (i % 3 == 1) {
                list.add(buildTableSeatList(i, seats));
            } else {
                list.add(buildSeatList(i, buildIdArray(seats)));
            }
        }
        return list;
    }

    private static List<RoomSeatData> buildTableSeatList(int rowCount, int[] ids) {
        List<RoomSeatData> dataList = new ArrayList<>();
        for (int i = 0; i < ids.length; i++) {
            int value = ids[i];
            if (value == -1) {
                dataList.add(null);
            } else {
                dataList.add(new RoomSeatData(rowCount, i, SeatType.seatTable, ""));
            }
        }
        return dataList;
    }

    private static List<RoomSeatData> buildSeatList(int rowCount, SparseIntArray idArray) {
        List<RoomSeatData> dataList = new ArrayList<>();
        for (int i = 0; i < idArray.size(); i++) {
            int id = idArray.get(i, -1);
            if (id == -1) {
                dataList.add(null);
                continue;
            }
            dataList.add(new RoomSeatData(rowCount, i, SeatType.seatNo, String.valueOf(id)));
        }
        return dataList;
    }

    private static SparseIntArray buildIdArray(int[] tableSeats) {
        SparseIntArray intArray = new SparseIntArray();
        for (int i = 0; i < tableSeats.length; i++) {
            intArray.put(i, tableSeats[i]);
        }
        return intArray;
    }
}
